<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('周转箱管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">箱型</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="mc" name="xx" placeholder="箱型"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">激活状态</label>
                        <select name="sfjh" lay-filter="aihao">
                            <option value=""></option>
                            <option value="">全部</option>
                            <option value="1">已激活</option>
                            <option value="0">未激活</option>
                        </select>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-normal" style="background-color: #40AFFE">重置</button>
                    </div>
                </form>
                <!--<div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>-->
                <div class="group-button tpl-button" id="toolbar">
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script th:inline="javascript">

    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate', 'tablebutton'], function () {

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;

        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                /*新增*/
                addEvent: function (data) {
                    add();
                },
                /*编辑*/
                editEvent: function (data) {
                    if (data.row != undefined) {
                        editDialog(data.row.id);
                    }
                },
                /*禁用*/
                disableEvent: function (data) {
                    if (data.row != undefined) {
                        stopDialog(data.row.id);
                    }
                },
                //启用
                enableEvent: function (data) {
                    if (data.row != undefined) {
                        startDialog(data.row.id);
                    }
                },
                //添加箱数
                getEvent: function (data) {
                    if (data.row != undefined) {
                       sumBox(data.row.id);
                    }
                },
                //扣减箱数
                deleteEvent: function (data) {
                    if (data.row != undefined) {
                        delBox(data.row.id);
                    }
                }
            }
        });

        //编辑
        function editDialog(id) {
                zzpUtils.dialog({
                    title: "修改周转箱",
                    type: 2,
                    content: "/box/editBox?id=" + id,
                    area: ['55%', '75%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
        }

        //禁用
        function stopDialog(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("是否确定禁用周转箱", function (index) {
                zzpUtils.action({
                    url: "/wmsturnoverbox/bjh" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            if(data.type=='success'){
                                layer.msg(data.title);
                            }else{
                                layer.msg(data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;

        }

        //启用周转箱
        function startDialog(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("是否确定启用周转箱", function (index) {
                zzpUtils.action({
                    url: "/wmsturnoverbox/yjh" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            if(data.type=='success'){
                                layer.msg(data.title);
                            }else{
                                layer.msg(data.message);
                            }
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }
        /*新增周转箱*/
       function add(){
            zzpUtils.dialog({
                title: "新增周转箱",
                type: 2,
                content: "/box/addBox",
                area: ['55%', '75%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
       }

        //箱数加
        function sumBox(id){
            var ids = [];
            ids.push(id);
            zzpUtils.dialog({
                title: "添加箱数",
                type: 2,
                content: "/box/addBoxNumber?id=" + ids,
                area: ['45%', '36%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
        //箱数减
        function delBox(id){
            var ids = [];
            ids.push(id);
            zzpUtils.dialog({
                title: "扣减箱数",
                type: 2,
                content: "/box/updateBoxNumber?id=" + ids,
                area: ['45%', '36%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        laydate.render({
            elem: '#test5'
            , theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            isOperate: true,
            pagination: true,
            url: '/wmsturnoverbox/list',
            columns: [/*{
                field: '',
                checkbox: true
            },*/ {
                field: 'xx',
                title: '箱型',
                width:200
            }, {
                field: 'c',
                title: '长',
                width:120
            }, {
                field: 'k',
                title: '宽',
                width:120
            }, {
                field: 'g',
                title: '高',
                width:120
            }, {
                field: 'xs',
                title: '箱数',
                width:100
            }, {
                field: 'sfjh',
                title: '激活状态',
                width:100,
                formatter: function (value, row, index) {
                    if (row.sfjh == 0) {
                        return [
                            '<a class="layui-btn layui-btn-primary layui-btn-xs" >禁用</a>'
                        ].join('')
                    } else {
                        return [
                            '<a class="layui-btn layui-btn-primary layui-btn-xs" >启用</a>'
                        ].join('')
                    }
                }
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter
        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var  button = '', buttons1 = '', buttons2 = '';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var btn = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.sfjh == '1') {//启用
                    if (functions.tableBtn[i].name == '编辑' || functions.tableBtn[i].name == '添加箱数'|| functions.tableBtn[i].name == '扣减箱数'|| functions.tableBtn[i].name == '禁用') {
                        buttons1 += btn;
                    }
                } else{
                    if (functions.tableBtn[i].name == '启用') {
                        buttons1 += btn;
                    }
                }
            }

            return buttons1;
        }
      /*  function operateFormatter1(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.sfjh == '1') {//启用
                    if (functions.tableBtn[i].name == '编辑' || functions.tableBtn[i].name == '添加箱数'|| functions.tableBtn[i].name == '扣减箱数'|| functions.tableBtn[i].name == '禁用') {
                        button += btn;
                    }
                } else{
                    if (functions.tableBtn[i].name == '启用') {
                        button += btn;
                    }
                }
            }
            button += '</span>'
                + '</div>';
            return button;
        }*/

    });

</script>
</html>